package com.samphanie.auiu.admin.controller;

import com.samphanie.auiu.admin.service.ISysRoleService;
import com.samphanie.auiu.common.dto.RoleDto;
import com.samphanie.auiu.common.utils.ApiResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * @author ZSY
 * @email 1451691457@qq.com
 */
@Api(tags = "角色管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/role")
public class RoleController {

    private final ISysRoleService roleService;

    @ApiOperation("所有角色列表")
    @GetMapping("/list")
    public ApiResponse<?> list() {
        return ApiResponse.success(roleService.listRoleList());
    }

    @ApiOperation("所有角色列表")
    @GetMapping("/getRolesNames")
    public ApiResponse<?> getRolesNames() {
        return ApiResponse.success(roleService.getRolesNames());
    }

    @ApiOperation("获取角色详细信息")
    @GetMapping(value = "/{id}")
    public ApiResponse<?> getInfo(@PathVariable("id") Long id) {
        return ApiResponse.success(roleService.getById(id));
    }

    @ApiOperation("新增角色")
    @PostMapping("/add")
    public ApiResponse<?> add(@RequestBody RoleDto roleDto) {
        return ApiResponse.success(roleService.add(roleDto));
    }

    @ApiOperation("修改角色")
    @PutMapping("/update")
    public ApiResponse<?> update(@RequestBody RoleDto roleDto) {
        return ApiResponse.success(roleService.updateRole(roleDto));
    }

    @ApiOperation("删除角色")
    @DeleteMapping("/delete")
    public ApiResponse<?> remove(@RequestBody Long[] ids) {
        return ApiResponse.success(roleService.removeByIds(Arrays.asList(ids)));
    }
    
}
